import 'package:flutter/material.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/pages/transcription/files/controllers/transcriptio_files_logic.dart';
import 'package:oramemo/pages/transcription/transcription_router.dart';
import 'package:oramemo/widget/gradient_app_head.dart';
import 'package:oramemo/widget/gradient_background.dart';
import 'package:oramemo/widget/my_refresh.dart';
import '../widgets/file_list_item.dart';
import 'package:oramemo/common/langs/text_key.dart';

class FileListPage extends StatelessWidget {
  const FileListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          GradientAppHead(
            title: TextKey.folderManagementTitle.tr,
            actions: TextButton(
              onPressed: () async {
                Get.toNamed(TranscriptionRouter.transcriptionFileAdd);
              },
              child: Text(
                TextKey.addButtonText.tr,
                style: const TextStyle(
                  color: Colors.black,
                  fontSize: 16,
                ),
              ),
            ),
          ),
          Expanded(
            child: GradientBackground(
              child: MyRefresh(
                onRefresh: () async {
                  Get.find<TranscriptionFilesLogic>().loadFolders();
                },
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      Container(
                        margin:
                            const EdgeInsets.fromLTRB(12.0, 10.0, 12.0, 0.0),
                        padding:
                            const EdgeInsets.fromLTRB(12.0, 0.0, 12.0, 0.0),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(12),
                        ),
                        child: GetBuilder<TranscriptionFilesLogic>(
                            builder: (logic) {
                          return Column(
                            children: [
                              for (final data in logic.list)
                                Column(
                                  children: [
                                    FileListItem(data: data),
                                    const Divider(height: 1),
                                  ],
                                ),
                            ],
                          );
                        }),
                      ),
                      const SizedBox(width: double.infinity, height: 300),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
